<template>
  <div class="app-container">
    <el-dialog :title="'快递修改'+'（'+form.orderNo+'）'" :visible.sync="dialogVisible" width="30%" append-to-body>
      <el-form ref="form" :model="form" v-loading="loading" label-position="top">
        <el-form-item label="快递公司" prop="expressId" required>
          <el-select v-model="form.expressId" filterable style="width: 100%">
            <el-option
              v-for="item in expressList"
              :key="item.id"
              :label="item.expressName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="详细地址" prop="recipientContent" required>
          <el-input type="textarea" v-model="form.recipientContent" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible=false">取 消</el-button>
        <el-button type="primary" @click="dialogOk" v-loading="loading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getToken} from "../../../../utils/auth";
import {payCustomOrder} from "../../../../api/imsMng";
import {updateSaleOrderExpress, uploadSaleOrderFile} from "../../../../api/saleMng";
import {listExpressShop} from "../../../../api/expressMng";

export default {
  dicts: ['ims_bank_name'],
  data() {
    return {
      loading: false,
      dialogVisible: false,
      form: {
        expressId:'',
        recipientContent:''
      },
      expressList:[]
    }
  },
  methods: {
    show(form) {
      this.dialogVisible = true
      this.form = {}
      this.resetForm('form')
      this.form.id = form.id
      this.form.orderNo = form.orderNo
      this.$set(this.form,'expressId',form.expressId)
      this.$set(this.form,'recipientContent',form.recipientContent)
      this.load()
    },
    load(){
      listExpressShop({pageSize:-1}).then(res=>{
        this.expressList=res.rows
      })
    },
    dialogOk() {
      this.$refs.form.validate(e => {
        if (e) {
          this.loading=true
          updateSaleOrderExpress(this.form).then(res => {
            this.$emit('ok')
            this.dialogVisible = false
            this.$message.success('修改成功')
          }).finally(e=>{
            this.loading=false
          })
        }
      })
    },
  }
}
</script>
